package com.ruoyi.pcwl.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pcwl.domain.ArticleContent;
import com.ruoyi.pcwl.service.IArticleContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * APP已发布文章内容Controller
 *
 * @author ruoyi
 * @date 2024-01-11
 */
@RestController
@RequestMapping("/pcwl/content")
public class ArticleContentController extends BaseController
{
    @Autowired
    private IArticleContentService articleContentService;

    /**
     * 查询APP已发布文章内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleContent articleContent)
    {
        startPage();
        List<ArticleContent> list = articleContentService.selectArticleContentList(articleContent);
        return getDataTable(list);
    }

    /**
     * 导出APP已发布文章内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:content:export')")
    @Log(title = "APP已发布文章内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleContent articleContent)
    {
        List<ArticleContent> list = articleContentService.selectArticleContentList(articleContent);
        ExcelUtil<ArticleContent> util = new ExcelUtil<ArticleContent>(ArticleContent.class);
        util.exportExcel(response, list, "APP已发布文章内容数据");
    }

    /**
     * 获取APP已发布文章内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:content:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(articleContentService.selectArticleContentById(id));
    }

    /**
     * 新增APP已发布文章内容
     */
    @PreAuthorize("@ss.hasPermi('system:content:add')")
    @Log(title = "APP已发布文章内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleContent articleContent)
    {
        return toAjax(articleContentService.insertArticleContent(articleContent));
    }

    /**
     * 修改APP已发布文章内容
     */
    @PreAuthorize("@ss.hasPermi('system:content:edit')")
    @Log(title = "APP已发布文章内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleContent articleContent)
    {
        return toAjax(articleContentService.updateArticleContent(articleContent));
    }

    /**
     * 删除APP已发布文章内容
     */
    @PreAuthorize("@ss.hasPermi('system:content:remove')")
    @Log(title = "APP已发布文章内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(articleContentService.deleteArticleContentByIds(ids));
    }
}
